package version1;

/**
 * 尾递归的写法
 */
public class RecursionDemo2 {

    public static void main(String[] args) {

        System.out.println(getFactorialOfN(4,1));
    }

    private static int getFactorialOfN(int n, int result) {
        //System.out.println(n+"--->");
        if(n < 0){
            throw new RuntimeException("请输入大于等于零的正整数！");
        }
        if(n == 0 || n == 1){
            return result;
        }else {
            return getFactorialOfN(n-1, n*result);
        }
        
    }
}
